{extend name="public/base"/}
{block name="body"}
<div class="main-box no-header clearfix">
    <header class="main-box-header clearfix">
        <div class="pull-left">
            <h2>{$meta_title}</h2>
        </div>
        <!--<div class="pull-right">
            <a href="{:url('add')}" class="btn btn-primary pull-right"> <i class="fa fa-plus-circle fa-lg"></i> 新增用户</a>
        </div>-->
    </header>
    <div class="main-box-body clearfix">
        <div class="navbar navbar-default">
            <form action="" class="navbar-form form-inline" method="get">
                <div class="form-group">
                    <label class="control-label" for="input-order-id">用户ID</label>
                    <div class="input-group">
                        <input type="number" min="0" name="uid" value="{$param['uid']|default=''}" placeholder="UID"
                               class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label" for="input-order-id">手机号</label>
                    <div class="input-group">
                        <input type="text" name="phone" value="{$param['phone']|default=''}" placeholder="手机号"
                               class="form-control">
                    </div>
                </div>

                <button class="btn btn-primary" type="submit"><i class="fa fa-search"></i> 筛选</button>
            </form>
        </div>

        <div class="table-responsive">
            <table class="table user-list table-hover">
                <thead>
                <tr>
                    <th>
                        <span>ID</span>
                    </th>
                    <th>
                        <span>用户昵称</span>
                    </th>
                    <th>
                        <span>手机号码</span>
                    </th>
                    <th>
                        <span>账户余额</span>
                    </th>
                    <th>
                        <span>待售金额</span>
                    </th>
                    <th>
                        <span>冻结金额</span>
                    </th>
                    <th>
                        <span>注册时间</span>
                    </th>
                    <th>
                        <span>注册来源</span>
                    </th>
                    <th>
                        <span>推荐人ID</span>
                    </th>

                    <th class="text-center">
                        <span>状态</span>
                    </th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>

                {volist name="list" id="item"}
                <tr>
                    <td><span>{$item['id']}</span></td>
                    <td><span>{$item['user_name']}</span></td>
                    <td><span>{$item['phone']}</span></td>

                    <td><span>{$item->Money->account_money}</span></td>
                    <td><span>{$item->Money->money_collect}</span></td>
                    <td><span>{$item->Money->money_freeze}</span></td>

                    <td><span>{$item['reg_time']}</span></td>
                    <td><span>{$item['reg_way_name']}</span></td>
                    <td><span>{$item['recommend_id']}</span></td>

                    <td><span>{$item['status_name']}</span></td>

                    <td>
                        <!--<a href="{:url('edit',array('id'=>$item['id']))}" class="table-link" title="">
                            编辑
                        </a>
                        <a href="{:url('auth',array('id'=>$item['id']))}" class="table-link">
                            授权
                        </a>
                        <a href="{:url('del',array('id'=>$item['id']))}" class="table-link confirm ajax-get">
                            删除
                        </a>-->

                        <!-- Single button -->
                        <div class="btn-group">
                            <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown"
                                    aria-haspopup="true" aria-expanded="false"> 详细菜单 <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li><a href="{:url('edit', ['id'=>$item['id']])}">编辑</a></li>

                                <li><a href="{:url('recharge/index', ['uid'=>$item['id']])}">充值</a></li>
                                <li><a href="{:url('withdraw/index', ['uid'=>$item['id']])}">提现</a></li>
                                <li><a href="{:url('money/index', ['uid'=>$item['id']])}">资金流水</a></li>
                                <li><a href="{:url('msg/index', ['uid'=>$item['id']])}">站内信</a></li>
                                <li><a href="{:url('user/address', ['uid'=>$item['id']])}">收货地址</a></li>

                            </ul>
                        </div>

                        <a class="btn btn-primary btn-sm " data-toggle="modal" href="#myModal"
                           data-whatever="{$item['phone']}"
                           data-uid="{$item['id']}">资金变更</a>

                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
            {$page}
        </div>
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
     style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Modal Tittle</h4>
            </div>
            <div class="modal-body">


                <form action="{:url('change')}" method="post" id="money_modal_form">
                    {:token()}
                    <div class="form-group">
                        <!--<label for="basic-url">Your vanity URL</label>-->
                        <div class="input-group">
                            <span class="input-group-addon" id="account_money">账户余额</span>
                            <input type="number" name="account_money" class="form-control"
                                   aria-describedby="account_money">
                        </div>
                        <span class="help-block">请输入金额 格式:0.00或 -0.00, 如果是负数则为减去金额</span>
                    </div>

                    <div class="form-group">
                        <!--<label for="basic-url">Your vanity URL</label>-->
                        <div class="input-group">
                            <span class="input-group-addon" id="money_collect">待收总额</span>
                            <input type="number" name="money_collect" class="form-control"
                                   aria-describedby="money_collect">
                        </div>
                        <span class="help-block">请输入金额 格式:0.00或 -0.00, 如果是负数则为减去金额</span>
                    </div>

                    <div class="form-group">
                        <!--<label for="basic-url">Your vanity URL</label>-->
                        <div class="input-group">
                            <span class="input-group-addon" id="money_freeze">冻结金额</span>
                            <input type="number" name="money_freeze" class="form-control"
                                   aria-describedby="money_freeze">
                        </div>
                        <span class="help-block">请输入金额 格式:0.00或 -0.00, 如果是负数则为减去金额</span>
                    </div>

                    <div class="form-group">
                        <!--<label for="basic-url">Your vanity URL</label>-->
                        <div class="input-group">
                            <span class="input-group-addon" id="info">变更备注</span>
                            <input type="text" name="info" class="form-control" aria-describedby="info" required>
                        </div>
                        <span id="info-msg-block" class="help-block alert-danger">备注信息必须明确填写，方便财务对账需要！</span>
                    </div>
                    <input type="hidden" name="uid" id="uid" value="">
                </form>


            </div>
            <div class="modal-footer">
                <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
                <button class="btn btn-primary" type="button" id="save_change">保存更改</button>
            </div>
        </div>
    </div>
</div>

{/block}

<block name="script">
    <script type="text/javascript">
        $(function () {
            //资金变更 - 展示modal框
            $('#myModal').on('show.bs.modal', function (event) {
                var button = $(event.relatedTarget); // Button that triggered the modal
                var recipient = button.data('whatever'); // Extract info from data-* attributes
                var uid = button.data('uid'); // Extract info from data-* attributes


                var modal = $(this);
                modal.find('.modal-title').text('账户资金变更： ' + recipient + '-' + uid);
                modal.find('.modal-body input[name=uid]').val(uid)
            });

            //具体变更逻辑
            $('#save_change').on('click', function (event) {
                //ajax post
                var $form = $('#money_modal_form');

                //判断备注信是否为空
                var $info = $form.find('input[name=info]').val();
                if ($info.length <= 0) {
                    $form.find('#info-msg-block').text('请输入备注信息！');
                    return false;
                }

                $.post($form.attr('action'), $form.serialize()).success(function (data) {
                    if (data.code) {
                        $('#myModal').modal('hide');
                        window.location.reload(true);
                    } else {
                        alert(data.msg);
                        return false;
                    }
                });
            });
        });

    </script>

</block>